﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Interop;
using System.Windows.Media.Imaging;

namespace MessageBoxWPF.Converter
{
    public class SystemIconConverter : IValueConverter
    {
        public object Convert(object value, Type type, object parameter, CultureInfo culture)
        {
            var typeImg = (MessageBoxType)value;

            System.Drawing.Icon si = System.Drawing.SystemIcons.Error;
            switch (typeImg)
            {
                case MessageBoxType.Error:
                    si = System.Drawing.SystemIcons.Error;
                    break;
                case MessageBoxType.Exclamation:
                    si = System.Drawing.SystemIcons.Exclamation;
                    break;
                case MessageBoxType.Information:
                    si = System.Drawing.SystemIcons.Information;
                    break;
                case MessageBoxType.Question:
                    si = System.Drawing.SystemIcons.Question;
                    break;
                case MessageBoxType.Warning:
                    si = System.Drawing.SystemIcons.Warning;
                    break;
            }

            BitmapSource bs = Imaging.CreateBitmapSourceFromHIcon(si.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
            return bs;
        }

        public object ConvertBack(object value, Type type, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}